import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* 固定不变的路由 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页公告', icon: 'icon-gonggao', affix: true }
      }
    ]
  },
  {
    path: '/tasklist',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/TaskList/index'),
        name: 'tasklist',
        meta: { title: '任务列表', icon: 'icon-renwu', noCache: true }
      }
    ]
  },
  {
    path: '/task_issue',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/TaskIssue/index'),
        name: 'task_issue',
        meta: { title: '发布任务', icon: 'icon-fabu', noCache: true }
      },
      {
        path: 'navtao',
        component: () => import('@/views/TaskIssue/components/Public.vue'),
        name: 'nav_tao',
        meta: { title: '淘精补', noCache: true },
        hidden: true
      },
      {
        path: 'navpin',
        component: () => import('@/views/TaskIssue/components/Public.vue'),
        name: 'nav_pin',
        meta: { title: '拼精补', noCache: true },
        hidden: true
      },
      {
        path: 'navjing',
        component: () => import('@/views/TaskIssue/components/Public.vue'),
        name: 'nav_jing',
        meta: { title: '京精补', noCache: true },
        hidden: true
      },
      {
        path: 'navdian',
        component: () => import('@/views/TaskIssue/components/Public.vue'),
        name: 'nav_dian',
        meta: { title: '垫付定制', noCache: true },
        hidden: true
      },
      {
        path: 'navgprs',
        component: () => import('@/views/TaskIssue/components/Public.vue'),
        name: 'nav_gprs',
        meta: { title: '流量定制', noCache: true },
        hidden: true
      },
      {
        path: 'navlives',
        component: () => import('@/views/TaskIssue/components/Public.vue'),
        name: 'nav_lives',
        meta: { title: '直播间定制', noCache: true },
        hidden: true
      },
      {
        path: 'navvideos',
        component: () => import('@/views/TaskIssue/components/Public.vue'),
        name: 'nav_videos',
        meta: { title: '短视频定制', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/mine_template',
    component: Layout,
    redirect: '/guide/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/MineTemplate/index'),
        name: 'mine_template',
        meta: { title: '我的模板', icon: 'icon-moban', noCache: true }
      }
    ]
  },
  {
    path: '/mine_store',
    component: Layout,
    redirect: '/guide/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/MineStore/index'),
        name: 'mine_store',
        meta: { title: '我的店铺', icon: 'icon-dianpu', noCache: true }
      }
    ]
  },
  {
    path: '/mine_count',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/MineCount/index'),
        name: 'mine_count',
        meta: { title: '我的账户', icon: 'icon-zhanghu' }
      }
    ]
  },

  {
    path: '/black_list',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/BlackList/index'),
        name: 'black_list',
        meta: { title: '黑名单', icon: 'icon-heimingdan' }
      }
    ]
  },

  {
    path: '/suggestions',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/Suggestions/index'),
        name: 'suggestions',
        meta: { title: '投诉建议', icon: 'icon-tousu' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

/* 动态路由 */
export const asyncRoutes = []

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    // scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
